package com.example.mainstream.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.shopapp.R;
import com.example.shopapp.bean.Goods;

public class GoodsAdapter extends BaseQuickAdapter<Goods, BaseViewHolder> {

    private IGoodsListener listener;
    private Context context;
    public GoodsAdapter(IGoodsListener listener,Context context) {
        super(R.layout.item_goods);
        this.context = context;
        this.listener = listener;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, Goods goods) {
        Glide.with(context).load(goods.getUrl()).into((ImageView) baseViewHolder.getView(R.id.img_url));
        baseViewHolder.setText(R.id.tv_title,goods.getTitle());
        baseViewHolder.setText(R.id.tv_price,"¥："+goods.getPrice());
        baseViewHolder.setText(R.id.tv_goodType,goods.getGoods_type());
        baseViewHolder.getView(R.id.card_view).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener!=null){
                    listener.onGoodsClick(goods);
                }
            }
        });
    }
}
